import { Controller, Get, Query, UseGuards, Req } from '@nestjs/common';
import { UserService } from './user.service';
import { UserRegisterModel } from '../model/user.dto';
import { AuthGuard } from '@nestjs/passport';

@Controller('user')
export class UserController {
  constructor(private readonly service: UserService) {}

  @UseGuards(AuthGuard('jwt'))
  @Get('/test')
  test(@Req() query: any) {

    const token = query.headers.authorization as string;
    const rawToken = token.split(' ').pop();
    return this.service.getTokenInfo(rawToken);
  }

  @Get('/register')
  register(@Query() query: UserRegisterModel) {
    return this.service.register(query);
  }
}
